package game;

import java.io.*;
import java.awt.*;
import java.net.*;
import java.applet.*;

import javax.swing.JButton;
import javax.swing.JLabel;

public class AppletCallingServlet extends Applet {
	URL url = null;
	URLConnection servletConnection = null;

	public void init() {
		try {
//			setBackground(Color.red);
			url = new URL("http://localhost:8080/examples/ServletExampl");
			servletConnection = url.openConnection();
			servletConnection.setDoInput(true);
			servletConnection.setDoOutput(true);
			servletConnection.setUseCaches(false);
			servletConnection.setDefaultUseCaches(false);
			servletConnection.setRequestProperty("Content-Type",
					"application/octet-stream");
			ObjectInputStream input = new ObjectInputStream(
					servletConnection.getInputStream());
			String str = new String();
			str = (String) input.readObject();
			add(new JButton(""));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void paint(Graphics g) {
		try {
			ObjectInputStream input = new ObjectInputStream(
					servletConnection.getInputStream());
			URL url2 = new URL(getCodeBase(), "gfx/ball20-red.gif");
			Image ima   = getToolkit().createImage(url2);
			g.drawImage(ima, 100, 100, null);
			g.drawString("Applet Servlet Communication", 50, 50);
			String str = new String();
			str = (String) input.readObject();
			showStatus(str);
			input.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}